﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class D09_Application1 : MonoBehaviour
{
    private List<string> logList = new List<string>();

    //常用基本功能
    private void OnGUI1()
    {
        if (GUILayout.Button("打开百度"))
        {
            Application.OpenURL("www.baidu.com");
        }
        if (GUILayout.Button("打开文件夹"))
        {
            Application.OpenURL("D:\\");
        }
        if (GUILayout.Button("拨号(移动端有效)"))
        {
            Application.OpenURL("tel:18181953293");
        }

        if (GUILayout.Button("退出游戏(编辑器无效)"))
        {
            Application.Quit();

#if UNITY_EDITOR //模拟退出
            UnityEditor.EditorApplication.ExitPlaymode();
#endif
        }
    }

    //响应日志信息
    private void Start()
    {
        Application.logMessageReceived += Fun;
        Application.wantsToQuit += Fun1;
    }

    private bool Fun1()
    {
        return false;//阻止退出
    }

    private void Fun(string condition, string stackTrace, LogType type)
    {
        switch (type)
        {
            case LogType.Error:
                logList.Add(condition + "\n" + stackTrace + "\n\n");
                break;
            case LogType.Assert:
                break;
            case LogType.Warning:
                break;
            case LogType.Log:
                break;
            case LogType.Exception:
                logList.Add(condition + "\n" + stackTrace + "\n\n");
                break;
            default:
                break;
        }
    }

    private void OnGUI()
    {
        if (GUILayout.Button("故意报错"))
        {
            int.Parse("A");
        }

        if (GUILayout.Button("退出游戏"))
        {
            Application.Quit();
        }

        foreach (var item in logList)
        {
            GUILayout.Label(item);
        }
    }
}
public class D09_Application : MonoBehaviour
{
    private void OnGUI()
    {
        if (GUILayout.Button("dataPath"))
        {
            print(Application.dataPath);
            Application.OpenURL(Application.dataPath);
        }

        if (GUILayout.Button("persistentDataPath"))
        {
            print(Application.persistentDataPath);
            Application.OpenURL(Application.persistentDataPath);
        }

        if (GUILayout.Button("streamingAssetsPath"))
        {
            print(Application.streamingAssetsPath);
            Application.OpenURL(Application.streamingAssetsPath);
        }
    }
}